package com.quanyan.ic.vendingMachine.protocol.client;

import com.quanyan.ic.vendingMachine.protocol.Cmd;
import com.quanyan.ic.vendingMachine.protocol.codec.protobuf.VmMessageBuilder;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by zhuo.shi on 2017/6/1.
 */
public class HandShakeReqHandler extends ChannelInboundHandlerAdapter {

    private static Logger logger = LoggerFactory.getLogger(HandShakeReqHandler.class);

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        VmMessageBuilder vmMessageBuilder = new VmMessageBuilder("0755-01-01");
        vmMessageBuilder.buildCmd(Cmd.HANDSHAKE_REQ);
        ctx.writeAndFlush(
                vmMessageBuilder.getMessage()
        ); //发送握手消息
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {


    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.fireExceptionCaught(cause);
    }

}
